package com.howells.time.module.account.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.howells.time.R;
import com.howells.time.base.activity.BaseActivity;
import com.howells.time.base.activity.CustomDialog;
import com.howells.time.base.utils.SharedPrefsUtil;
import com.howells.time.base.utils.StatusBarUtil;
import com.howells.time.base.utils.ToastShow;
import com.howells.time.module.UIHelper;
import com.howells.time.module.account.presenter.AccountPresenter;
import com.howells.time.module.account.presenter.AccountPresenterImp;

/**
 * Created by Administrator on 2016.5.8.
 */
public class AccountActivity extends BaseActivity implements AccountView{

    private AccountPresenter accountPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account);
        StatusBarUtil.setColor(this,0);
        accountPresenter=new AccountPresenterImp(this);
        ((TextView)findViewById(R.id.top_pannel_title)).setText("账号和安全");
    }

    public void onClick(View view){
        switch (view.getId()){
            case R.id.top_pannel_back:
                finish();
                break;
            case R.id.account_verify_layout_modify_password:
                UIHelper.jumpChangePsw(this);
                break;
            case R.id.account_verify_layout_binding_telephone:
                ToastShow.ToastShort(this,"没有此功能");
                break;
            case R.id.account_verify_layout_out:
                signout();
                break;
        }
    }

    private void signout() {
        final CustomDialog customDialog = new CustomDialog(this, "注销", "确定要退出吗?","确定", "取消");
        customDialog.show();
        customDialog.setDialoglistener(new CustomDialog.Dialoglistener() {
            @Override
            public void onclick(View view) {
                switch (view.getId()) {
                    case R.id.view_common_dialog_left_button:
                        accountPresenter.signout();
                        customDialog.cancel();
                        break;
                    case R.id.view_common_dialog_right_button:
                        customDialog.cancel();
                        break;
                    default:
                        customDialog.cancel();
                        break;
                }
            }
        });
    }

    @Override
    public void logoutsuccess() {
        SharedPrefsUtil.putValue(this,"UserInfo","username",null);
        SharedPrefsUtil.putValue(this, "UserInfo", "password", null);
        ToastShow.ToastShort(this, "退出成功");

        Intent intent=new Intent();
        intent.putExtra("main",1);
        UIHelper.jumpMain(this,intent);
    }
}
